﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace proj1
{
    public partial class Form : System.Windows.Forms.Form
    {
        public Form()
        {
            InitializeComponent();
        }

        private void btnquit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnclear_Click(object sender, EventArgs e)
        {
            //Clear Extended total
            lblextended1.Text = "";
            lblextended2.Text = "";
            lblextended3.Text = "";
            //Clear labels in control panel
            lblVsub.Text = "";
            lblVtax.Text = "";
            lblVtotal.Text = "";
            //Numerical Up Downs
            numericUpDown1.Value = 0;
            numericUpDown2.Value = 0;
            numericUpDown3.Value = 0;
            //Clear invoice number
            mtxid.Text = "";
            // Set focus to invoice number
            mtxid.Focus();
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            decimal extended1 = 0.0m;
            extended1 = numericUpDown1.Value * 950;  
            lblextended1.Text = extended1.ToString("C");
            item1.set_quantity((int)numericUpDown1.Value);
            item1.set_extended(extended1);
        }

        private void numericUpDown2_ValueChanged(object sender, EventArgs e)
        {
            decimal extended2 = 0.0m;
            extended2 = numericUpDown2.Value * 480;
            lblextended2.Text = extended2.ToString("C");
            item2.set_quantity((int)numericUpDown2.Value);
            item2.set_extended(extended2);
        }

        private void numericUpDown3_ValueChanged(object sender, EventArgs e)
        {
            decimal extended3 = 0.0m;
            extended3 = numericUpDown3.Value * 315;
            lblextended3.Text = extended3.ToString("C");
            item3.set_quantity((int)numericUpDown3.Value);
            item3.set_extended(extended3);
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void clearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Clear Extended total
            //lblextended1.Text = ;
            //lblextended2.Text = ;
            //lblextended3.Text = "";
            //Clear labels in control panel
            lblVsub.Text = "";
            lblVtax.Text = "";
            lblVtotal.Text = "";
            //Numerical Up Downs
            numericUpDown1.Value = 0;
            numericUpDown2.Value = 0;
            numericUpDown3.Value = 0;
            //Clear invoice number
            mtxid.Text = "";
            // Set focus to invoice number
            mtxid.Focus();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            about.Show();
        }

        private void btncalculate_Click(object sender, EventArgs e)
        {
           
            int val = 0;
            Console.WriteLine(mtxid.Text);
            try
            {
                val = Int32.Parse(mtxid.Text);
            }
            catch(Exception)
            {
                val = 1;
            }

            if (val > 10000 || val < 999)
            {
                error.Show();
                return;
            }
            else
            {
                //Console.WriteLine(val);
                invoice.set_quantity(item1.get_quantity(), item2.get_quantity(), item3.get_quantity());
                invoice.calculate();
                lblVsub.Text = invoice.get_subtotal().ToString("C");
                lblVtax.Text = invoice.get_tax().ToString("C");
                lblVtotal.Text = invoice.get_total().ToString("C");
            }
        }

        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CaptureScreen();
            printform.Print();
        }

    }
}
